package com.yansl.http.proxy;

import java.lang.reflect.Proxy;

import org.springframework.beans.factory.FactoryBean;

/**
 * @description: Http接口代理类
 * @author: eshengtai
 * @create: 2022-12-17 11:33
 */
public class HttpProxy implements FactoryBean {
    private Class httpClass;

    private HttpHandler httpHandler;

    public HttpProxy(Class clazz) {
        this.httpClass = clazz;
    }

    @Override
    public Object getObject() throws Exception {
        return Proxy.newProxyInstance(httpClass.getClassLoader(), new Class[] { httpClass }, httpHandler);
    }

    @Override
    public Class<?> getObjectType() {
        return httpClass;
    }

    public void setHttpHandler(final HttpHandler httpHandler) {
        this.httpHandler = httpHandler;
    }
}
